<template>
    <div class="content-view">
        <treeView :left="left"></treeView>
        <i class="close-button el-icon-back" @click="closeContent"></i>
        <div class="moveBar" :style="{'left' : left - 2 +'px'}" @mousedown="mousedown($event)"></div>
        <APIContent :left="left"></APIContent>
    </div>
</template>

<script>
import treeView from './tree.vue'
import APIContent from './APIContent.vue'

export default {
    components: {
        treeView,
        APIContent
    },
    data() {
        return {
            left: 300
        }
    },
    methods: {
        closeContent() {
            this.$bus.$emit('show-card')
        },
        mousedown() {
            document.body.style.cursor = 'col-resize';
            document.onmousemove = (event) => {
                let left = event.clientX;
                if (left < 250) {
                    left = 250
                } else if (left > document.body.clientWidth - 500) {
                    left = document.body.clientWidth - 500
                }
                this.left = left;
            };
            document.onmouseup = () => {
                document.body.style.cursor = '';
                document.onmousemove = null;
                document.onmouseup = null;
            }
        },
    }
}
</script>

<style scoped>
.content-view {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.close-button {
    display: block;
    position: absolute;
    width: 30px;
    height: 30px;
    top: 15px;
    left: 10px;
    color: #999;
    text-align: center;
    line-height: 30px;
    font-size: 20px;
    cursor: pointer;
    transition: 0.3s all;
}
.close-button:hover {
    color: #333;
}

.moveBar {
    height: 100%;
    position: absolute;
    top: 0;
    width: 5px;
}
.moveBar::after {
    content: "";
    display: block;
    width: 2px;
    height: 100%;
    border-right: 1px solid rgba(0, 0, 0, 0.1);
}
.moveBar:active {
    background: rgba(0, 0, 0, 0.3);
}
.moveBar:hover {
    background: rgba(0, 0, 0, 0.3);
    cursor: col-resize;
}
</style>